 var apps, views, merchant;
mui.init({
	beforeback:function(){
		mui.fire(views.opener(), 'reloading');
	}
});


mui.plusReady(function () {
    views = bexta.getWebview();
    merchant = bexta.getStorage(MERCHANT);
   bexta.ajax(api.order_detail, function(res){
   		initVue(res);
   }, {data:{uid:merchant.uid, order_no:views.order}})
});
function initVue(res){
	apps = new Vue({
		el:"#vueMain",
		data:{
			list:res
		},
		mounted:function(){
			document.querySelector('.loading').classList.add('loadRun');
			mui('.mui-scroll-wrapper').scroll();	
			var self = this;
			if( this.list.order_status == 1 ){
				document.querySelector('.refuse').style.display = 'block';
			}else if( this.list.order_status == 5 ){
				document.querySelector('.finish').style.display = 'block';
			}else if( this.list.order_status == 7 ){
				document.querySelector('.audit').style.display = 'block';
			}
			document.querySelector('.refuse .yellow').setAttribute('_extras', 'order='+self.list.order_no);
			document.querySelector('.audit .link').setAttribute('_extras', 'order='+self.list.order_no);
//			_id="finish" _href="finish.html" _title="确认完工"
			document.querySelector('.finishbtn').addEventListener('tap', function(){
				var o = {
					name:self.list.name,
					img:self.list.img,
					order_amount:self.list.order_amount,
					order:self.list.order_no,
					stro:self.list.stro,
					amount:self.list.amount
				};
				bexta.openWithTitle({
					id:'finish',
					url:'finish.html',
					extras:{
						list:o
					}
				},{
					title:{
						text:"确认完工"
					}
				})
			});
			
			
			mui.each(document.querySelectorAll('.totl'), function(){
				this.innerHTML = self.list.order_amount;
			});
			
			//接单
			mui('body').on('tap', '.accept', function(){
				mui.confirm("确定要接受这个订单吗?", "影伴", CONFIRM, function(item){
					if( item.index == 1 ){
						bexta.ajax(api.check_order, function(res,msg){
							mui.toast(msg);
							if( !res ){
								views.reload();
//								views.opener().reload();
							}
						},{data:{uid:merchant.uid, order_no:self.list.order_no,method:1}});
					}
				});
			});
			
			
		}
	});
}
